package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.dao.CstTypeMapper;
import com.zxc.entity.CstType;
import com.zxc.service.CstTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CstTypeServiceImpl extends ServiceImpl<CstTypeMapper, CstType> implements CstTypeService {

    @Autowired
    private CstTypeMapper cstTypeMapper;

    @Override
    public List<CstType> getCstTypeService() {
        List<CstType> cstTypeList = cstTypeMapper.selectList(new QueryWrapper<>());
        return cstTypeList;
    }

    @Override
    public String getCstTypeNameById(String svrType) {
        CstType cstType = cstTypeMapper.selectById(svrType);
        return cstType.getTypeName();
    }

    @Override
    @Transactional
    public String[] getAllCstTypeName(){
        String[] cstTypeName = cstTypeMapper.getAllCstTypeName();
        return cstTypeName;
    }

    @Override
    @Transactional
    public int deleteByTypeName(List<String> deleteTypeName) {
        int result = cstTypeMapper.deleteByTypeName(deleteTypeName);
        return result;
    }

    @Override
    @Transactional
    public int saveCstType(CstType cstType) {
        int result = cstTypeMapper.insert(cstType);
        return result;
    }

    @Override
    public CstType getCstTypeByTypeName(String searchName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("type_name",searchName);
        CstType cstType = cstTypeMapper.selectOne(queryWrapper);
        return cstType;
    }
}
